/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BasicInfoPanel.java
 *
 * Created on Oct 6, 2010, 4:12:49 AM
 */

package com.celephais.objectGenerator;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.filechooser.FileFilter;

/**
 *
 * @author Eugene Shen
 */
public class BasicInfoPanel extends javax.swing.JPanel {

	private static final long serialVersionUID = -742515149885086472L;
	
	private ObjectGenerator parent;

    /** Creates new form BasicInfoPanel */
    public BasicInfoPanel(ObjectGenerator parent) {
		super();
		this.parent = parent;
        initComponents();
		additionalInitComponents();
    }

	public String getSourceDir() {
		return srcDirField.getText();
	}

	public String getSourcePkgName() {
		return pkgNameField.getText();
	}

	public String getObjName() {
		return objNameField.getText();
	}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        srcDirLabel = new JLabel();
        srcDirField = new JTextField();
        srcDirBrowseBtn = new JButton();
        pkgNameLabel = new JLabel();
        pkgNameField = new JTextField();
        objNameLabel = new JLabel();
        objNameField = new JTextField();
        btnPanel = new JPanel();
        generateBtn = new JButton();

        setName("Form"); // NOI18N

        srcDirLabel.setText("Code Generation Source Directory");
        srcDirLabel.setName("srcDirLabel"); // NOI18N

        srcDirField.setText("Source Directory");
        srcDirField.setToolTipText("Enter the source directory of this object (e.g. C:\\Dev\\Java\\Workout\\Common\\src\\com\\celephais\\common)"); // NOI18N
        srcDirField.setName("srcDirField"); // NOI18N

        srcDirBrowseBtn.setText("Browse...");
        srcDirBrowseBtn.setToolTipText("Browse for the source directory");
        srcDirBrowseBtn.setName("srcDirBrowseBtn"); // NOI18N

        pkgNameLabel.setText("Package Name of Source Directory");
        pkgNameLabel.setName("pkgNameLabel"); // NOI18N

        pkgNameField.setText("Package.Name");
        pkgNameField.setToolTipText("Enter the package name of the Source Directory specified above.");
        pkgNameField.setName("pkgNameField"); // NOI18N

        objNameLabel.setText("Object Name");
        objNameLabel.setName("objNameLabel"); // NOI18N

        objNameField.setText("ObjectName");
        objNameField.setToolTipText("Enter the name of your object.  CamelCase is highly recommended.");
        objNameField.setName("objNameField"); // NOI18N

        btnPanel.setName("btnPanel"); // NOI18N

        generateBtn.setFont(new Font("Arial Black", 0, 18)); // NOI18N
        generateBtn.setForeground(new Color(0, 51, 153));
        generateBtn.setText("Generate!");
        generateBtn.setToolTipText("Generate the objects");
        generateBtn.setName("generateBtn"); // NOI18N
        btnPanel.add(generateBtn);

        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(srcDirLabel)
                .addContainerGap())
            .addComponent(btnPanel, GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pkgNameLabel)
                .addContainerGap(190, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(objNameLabel)
                .addContainerGap(314, Short.MAX_VALUE))
            .addGroup(Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(Alignment.TRAILING)
                    .addComponent(objNameField, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)
                    .addComponent(pkgNameField, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE)
                    .addComponent(srcDirField, GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE))
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(srcDirBrowseBtn, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(srcDirLabel)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(srcDirField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(srcDirBrowseBtn))
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addComponent(pkgNameLabel)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(pkgNameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addComponent(objNameLabel)
                .addPreferredGap(ComponentPlacement.RELATED)
                .addComponent(objNameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(ComponentPlacement.RELATED, 78, Short.MAX_VALUE)
                .addComponent(btnPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

	private void additionalInitComponents() {
		fileChooser = new JFileChooser();
		fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		fileChooser.setFileFilter(new FileFilter() {
			@Override
			public boolean accept(File f) {
				if (f.isDirectory()) {
					return true;
				}
				else {
					return false;
				}
			}

			@Override
			public String getDescription() {
				return "Directories";
			}
		});
		srcDirBrowseBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int result = fileChooser.showOpenDialog(BasicInfoPanel.this);
				if (result == JFileChooser.APPROVE_OPTION) {
					srcDirField.setText(fileChooser.getSelectedFile().getPath());
				}
			}
		});

		generateBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				parent.generateCode();
			}
		});
	}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JPanel btnPanel;
    private JButton generateBtn;
    private JTextField objNameField;
    private JLabel objNameLabel;
    private JTextField pkgNameField;
    private JLabel pkgNameLabel;
    private JButton srcDirBrowseBtn;
    private JTextField srcDirField;
    private JLabel srcDirLabel;
    // End of variables declaration//GEN-END:variables

	private JFileChooser fileChooser;
}
